Added Number_Theory_Algorithms under include directory#44
Added Number_Theory_Algorithms under include directory#44yadvendra20 wants to merge 1 commit intomoghya:masterfrom
Conversation
… some cases in array.h where memory allocation may fail
moghya
left a comment
There was a problem hiding this comment.
Thank you @yadvendra20 . Please take a look at the comments.
| #include "include/heap.h" | ||
| #include "include/graph.h" | ||
|
|
||
| #include "include/Number_Theory_Algorithms/fundamental_functions.h" |
There was a problem hiding this comment.
please change name of directory to be small case
| * More about binary exponentiantion: https://cp-algorithms.com/algebra/binary-exp.html | ||
| */ | ||
|
|
||
| long long binaryExponentiation(long long base, long long exponent) { |
There was a problem hiding this comment.
Consider effects of bits when dealing with small number but not similar data type
| } | ||
|
|
||
| /* | ||
| * Modular binary exponentiation |
There was a problem hiding this comment.
Mention details about the algorithms
There was a problem hiding this comment.
Maybe the reference used to implement this particular algo.
| namespace dsa { | ||
|
|
||
| // returns true if the number is prime otherwise returns false | ||
|
|
| } | ||
|
|
||
| // Sieve of eratosthenes | ||
|
|
| * More about sieve of eratosthenes: https://cp-algorithms.com/algebra/sieve-of-eratosthenes.html | ||
| */ | ||
|
|
||
| array<bool> sieve(long long int number) { |
There was a problem hiding this comment.
can this use some sort of optimisation ? making is_prime static or similar other optimisations ?
maybe a object which can be reset with different limit later that again internally just increases length of array
| capacity=size+spare; | ||
| objs = new type[capacity]; | ||
| if(!objs) | ||
| throw "Memory allocation failed"; |
There was a problem hiding this comment.
need to do this across lib. a wrapper around new should be implemented in this, could you please file a ticket for that and we can take it up.
Added some utility functions and algorithms in Number Theory and handled some cases in "array.h" where memory allocation may fail. Also wrote the tests under "tests.h".